package com.efeichong.common.security;

import com.efeichong.common.domain.ResponseData;
import com.efeichong.common.utils.ResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author lxk
 * @date 2020/9/4
 * @description 权限认证失败统一处理
 */
@Slf4j
public class RestfulAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request,
                       HttpServletResponse response,
                       AccessDeniedException accessDeniedException) {
        log.warn("无权操作该功能:" + request.getRequestURI(), accessDeniedException);
        ResponseUtils.format(response, ResponseData.failure("无权操作该功能！"));
    }
}